<template>
  <div class="excess-page-container">
    <div class="loader"></div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { flatTreeData } from "@/utils/util.js";
export default {
  computed: {
    ...mapGetters(["menuData", "tenantData", "userAccount"]),
  },
  mounted() {
    this.getMenuJump();
  },
  methods: {
    ...mapActions(["Logout"]),
    getMenuJump() {
      let { userAccount = "" } = this;
      if (userAccount) {
        switch (userAccount) {
          //项目列表-有公司级权限
          case "projectListPage":
            this.$router.push({
              path: "/projectHome",
            });
            break;
          //项目列表-无公司级权限
          case "projectListPageNoGS":
            this.$router.push({
              path: "/projectHome",
            });
            break;
          //项目大屏
          case "projectDPPage":
            this.$router.push({
              path: "/largeScreen",
            });
            break;
          //功能菜单
          case "moudlePage":
            this.dealWithMenu();
            return;
            this.$router.push({
              //   path: "/system/portal/index",
              path: "/whitePage/index",
            });
            break;
          default:
            break;
        }
      } else {
        return this.Logout({})
          .then(() => {
            setTimeout(() => {
              this.$router.push({
                path: "/user/login?type=private",
              });
            }, 16);
          })
          .catch((err) => {});
      }
    },
    async dealWithMenu() {
      //首页信息
      let portalSource = JSON.parse(
        localStorage.getItem("PORTAL_ROUTERS_DATA" ?? "[]")
      );

      //默认获取一级节点菜单
      let flatMenu = flatTreeData(this.menuData, "children");
      let firstMenu = flatMenu.find(
        (v) => !v.children || v.children.length == 0
      );
      //没有首页，有菜单
      if (portalSource.length == 0 && this.menuData.length != 1) {
        this.$router.push({
          path: firstMenu.fullPath,
        });
      }
      //没有首页，没有菜单
      else if (portalSource.length == 0 && this.menuData.length == 1) {
        this.$router.push({
          path: `/whitePage/index`,
        });
      }
      //有首页，有菜单
      else {
        this.$router.push({
          path: "/system/portal/index",
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.excess-page-container {
  height: 100%;
  width: 100%;
  background: #1b2832;
  display: flex;
  justify-content: center;
  align-items: center;
  .loader {
    width: 85px;
    height: 50px;
    --g1: conic-gradient(from 90deg at left 3px top 3px, #0000 90deg, #fff 0);
    --g2: conic-gradient(
      from -90deg at bottom 3px right 3px,
      #0000 90deg,
      #fff 0
    );
    background: var(--g1), var(--g1), var(--g1), var(--g2), var(--g2), var(--g2);
    background-position: left, center, right;
    background-repeat: no-repeat;
    animation: l9 1s infinite;
  }
  @keyframes l9 {
    0% {
      background-size: 25px 50%, 25px 50%, 25px 50%;
    }
    25% {
      background-size: 25px 100%, 25px 50%, 25px 50%;
    }
    50% {
      background-size: 25px 50%, 25px 100%, 25px 50%;
    }
    75% {
      background-size: 25px 50%, 25px 50%, 25px 100%;
    }
    100% {
      background-size: 25px 50%, 25px 50%, 25px 50%;
    }
  }
}
</style>
